如何在react 您所在的位置:网站首页 electron child_processspawn 如何在react

如何在react

#如何在react| 来源: 网络整理| 查看: 265

需要注意的是,由于您要尝试派生多个进程,因此需要将它们存储在数组中而不是变量中,或者使用两个变量,每个按钮/进程派生一个变量,因为每次单击两个hello按钮中的任何一个时,process变量中的进程都会被覆盖,因为它们会发出相同的事件,并且会被两个cancel按钮中的任何一个杀死。

如果你想要有相同数量的按钮,也就是你创建的两个按钮,那么可以这样做:

// Backend let process1, process2 = null ipcMain.on("runScript", (event, data) => { if(data.process == 1) process1 = spawn('node helloworld.js', [], { shell: true }); else if(data.process == 2) process2 = spawn('node helloworld.js', [], { shell: true }) }); ipcMain.on("killScript", (event, data) => { if(data.process == 1) { kill(process1.pid, 'SIGKILL'); } else if (data.process == 2) kill(process2.pid, 'SIGKILL'); });// Client side ipcRenderer.send('runScript', {process: 1})}>hello ipcRenderer.send('killScript', {process: 1})}>cancel ipcRenderer.send('runScript', {process: 2})}>hello ipcRenderer.send('killScript', {process: 2})}>cancel

如果你有一个可变数量的按钮,你需要在后端使用一个数组来实现相同的解决方案,并且{process: processNumber}还需要与后端的进程数组中的正确进程相对应。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有